<?php

declare(strict_types=1);
/**
 *​小程序活动管理
 * User：Abell
 * Date：2020/4/20
 * Time：11:11
 */

namespace App\Controller\Api;

use App\Constants\ErrorCode;
use App\Controller\AbstractController;
use App\Utils\ApiUtils;
use App\Validate\ArticleValidation;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Di\Annotation\Inject;
use App\Service\WxnoticeService;
//ArticleService
use App\Service\ArticleService;

class WxnoticeController extends AbstractController
{
    /**
     * @Inject
     * @var WxnoticeService
     */
    protected $service;

    /**
     * @Inject
     * @var ArticleService
     */
    protected $article_service;

    /** 小程序活动页获取 默认获取最后一个
     * @Author abell
     * @DateTime 2020-05-27
     * @return object
     */
    public function getNotice(RequestInterface $request){
        return $this->jsonApi($this->service->getNotice($request->all()));
    }

    /** 小程序活动页列表页获取
     * @Author abell
     * @DateTime 2020-05-27
     * @return object
     */
    public function listNotice(){
        return $this->jsonApi($this->service->listNotice());
    }

    /** 小程序资讯列表
     * @Author abell
     * @DateTime 2020-06-18
     * @return object
     */
    public function articleList(){
        $page = $this->request->input('page',1);
        $pageSize = $this->request->input('pageSize',15);
        $order = $this->request->input('order','add_time desc');
        $result = $this->article_service->listApi($page,$pageSize,$order);
        return $this->response->json(ApiUtils::send(ErrorCode::SUCCESS,'ok',$result['data'],$result['total']));
    }

    /** 小程序获取单条资讯
     * @Author abell
     * @DateTime 2020-06-18
     * @return object
     */
    public function articleLast(){
        make(ArticleValidation::class)->check($this->request->all(),'edit_show')->response();
        $result = $this->article_service->editShow($this->request->input('id'));
        return $this->response->json(ApiUtils::send(ErrorCode::SUCCESS,'ok',$result[0],1));
    }
}